{% include 'admin/header.html' %}

<script type="text/javascript">
    changeTab('个人设置');
</script>

<div class="setting-xcontent">
    <div>
        <div class="col-lg-12 col-xs-12">
            <h4><span class="fa fa-hand-o-right"></span> 个人设置</h4>
        </div>
        <div class="col-lg-4 col-xs-4 col-lg-offset-1 col-xs-offset-1">
            <div class="panel panel-info bd-color-x">
                <div class="panel-heading bg-color-x">
                    <span class="">修改密码</span>
                </div>
                <div class="panel-body">
                    <form id="pwd" class="form-horizontal" method="post">
                        <input class="hidden" type="text" name="old_name" value="{{ admin.ad_name }}">
                        <div class="form-group">
                            <label for="np1" class="text-left col-sm-3 control-label">新密码</label>
                            <div class="col-sm-9">
                                <input type="password" name="ad_pass" class="form-control" id="np1" placeholder="新密码"
                                       required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="np2" class="text-left col-sm-3 control-label">确定密码</label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control" id="np2" placeholder="确定密码" required>
                            </div>
                        </div>
                        <input type="submit" value="确定修改" class="btn btn-warning btn-group-justified">
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-xs-4 col-lg-offset-1 col-xs-offset-1">
            <div class="panel panel-info bd-color-x">
                <div class="panel-heading bg-color-x">
                    <span class="">修改信息</span>
                </div>
                <div class="panel-body">
                    <form id="info" class="form-horizontal" method="post">
                        <input class="hidden" type="text" name="old_name" value="{{ admin.ad_name }}">
                        <div class="form-group">
                            <label for="np1" class="text-left col-sm-3 control-label">新电话</label>
                            <div class="col-sm-9">
                                <input type="text" name="ad_tel" class="form-control" maxlength="11" placeholder="{{ admin.ad_tel }}" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="np2" class="text-left col-sm-3 control-label">老师称呼</label>
                            <div class="col-sm-9">
                                <input type="text" name="teacher_name" class="form-control" placeholder="{{ admin.teacher_name }}">
                            </div>
                        </div>
                        <input type="submit" value="确定修改" class="btn btn-success btn-group-justified">
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('form').submit(function (event) {
        event.preventDefault();
        var fd = $(this).serialize();
        var ft = $(this).attr('id');
        if (ft === 'pwd') {
             var p1 = $('#np1').val();
             var p2 = $('#np2').val();
             if (p1.length < 6) {
                 alert("密码不能小于6位");
                 return;
             } else if (p1 !== p2) {
                 alert("两次密码不相同！");
                 return;
             }
        } else {
            var tel = $('[name="ad_tel"]').val();
            if (!/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel)) {
                alert("电话号码格式不正确！");
                return;
            }
        }
        $.post('/admin/change', fd, function (data) {
            if (data.status) {
                alert('SUCCESS: ' + data.msg);
                if (ft === 'pwd')
                    location.href = "/admin/login";
                else
                    location.href = '/admin/';
            } else {
                alert("ERROR: " + data.msg);
            }
        });
    });
</script>
{% include 'admin/footer.html' %}